#pragma once
#include "RequestQueue.h"
#include <math.h>

class Server
{
public:
    Server(RequestQueue* requestQueue, std::string name, long seed)
        : requestQueue(requestQueue), name(name), seed(seed)
    {
    }

public:
    const std::string getName()
    {
        return name;
    }
    const long getSeed()
    {
        return seed;
    }
    RequestQueue* getRequestQueue()
    {
        return requestQueue;
    }

private:
    RequestQueue*       requestQueue;
    const std::string   name;
    const long          seed;
};

class ServerThread
{
public:
    static unsigned __stdcall run(void* p)
    {   
        Server* server = (Server*)p;
        srand(server->getSeed());

        for(int i = 0; i < 10000; i++)
        {
            Request* r = server->getRequestQueue()->getRequest();
            std::string s(server->getName() + " handles  " + r->toString());
            printf("%s\n", s.c_str());
            Sleep(rand()%1000);
        }       

        return 0;
    }
};
